home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.11 Nov 90 / NeuralNet Estimator⁄EDIT / Neural Network.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-03  |  6.0 KB  |  170 lines  |  [TEXT/KAHL]

  1. /* Constants and structure definitions */
  2.  
  3. #define _MC68881_
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7.  
  8. #define MaxLay         5
  9. #define ActiveNets    4
  10.  
  11. /*---- return codes for linesearch ----*/
  12. #define LINEOK         0    /* if satisfactory new parm value found in linesearch */
  13. #define LINENOTOK     1     /* if linesearch can't find a step small enough to reduce SS */
  14.  
  15. /*---- return codes for gradient methods ----*/
  16. #define FAIL         0    /* if current parm value is not an approximate critical point */
  17. #define METGRADTOL    1    /* if norm of scaled gradient less than gradtol */
  18. #define METSTEPTOL    2    /* if scaled step is less than steptol */
  19. #define LINEFAIL    4    /* if linesearch failed to find next parm distinct from current value */
  20. #define EXCEDITNLIM 8    /* if iteratation limit exceeded */
  21. #define SINGJAC        16    /* if Jacobian is singular */
  22. #define NETSAT        32    /* if network is possible oversaturated */
  23.  
  24. /*---- codes used in Hooke & Jeeves search method ----*/
  25. #define CHANGED        1    /* if weight was changed in last search iteration */
  26.  
  27. /*---- codes for type of network ----*/
  28. #define SigUB        1    /* code for unbiased Sigma network */
  29. #define SigB        2    /* biased Sigma network */
  30. #define Lin            3    /* Linear model */
  31.  
  32. /* codes for squashing function */
  33. #define Logistic    1    /* logistic squashing function */
  34. #define hyperTan    2    /* hypebolic tangent */
  35. #define Thresh        3    /* threshold squashing function */
  36.  
  37. /* codes for estimation method */
  38. #define BackProp    1    /* code for Back Propagation estimation method */
  39. #define SimAnn        2    /* Simulated annealing */
  40. #define GaussNew    3    /* Gauss Newton method */
  41. #define qGaussNew    4    /* quasi Gauss Newton method, corrects for singular Jacobian */
  42. #define qNewton        5    /* quasi Newton method */
  43. #define HookeJeeves    6    /* Hooke and Jeeves method for direct search */
  44.  
  45. #define DataType double    /* specify the type of data used */
  46.  
  47. typedef struct                    /* type for a matrix of floating values        */
  48.     {
  49.     int rows,cols;
  50.     double ** cells;
  51.     }                    DTypeMatrix;
  52.     
  53. typedef struct                    /* type for a vector of floating values        */
  54.     {
  55.     int rows;
  56.     double ** cells;
  57.     }                    DTypeVector;
  58.  
  59. typedef struct                    /* type for neural network data structure    */
  60.     {
  61.     unsigned int OutLayer;        /* index of output layer in network, 1 less than # layers, must be less than MaxLayers */
  62.     unsigned int Units[MaxLay];    /* number of units in each layer */
  63.     DTypeMatrix W[MaxLay-1];    /* weight matrices for each layer except output    */
  64.     double    gradtol;            /* criteria for maximum used on gradient */
  65.     double    steptol;            /* criteria for convergence used on parameter step */
  66.     double     maxstep;            /* max step size, zero => no limit */
  67.     double    maxrelstep;            /* max relative step permited */
  68.     unsigned int itnlimit;        /* limit on the number of iterations */
  69.     short int usemaxstep;        /* flag to impose max step limit on gradient methods */
  70.     short int type;                /* the type of network */
  71.     short int method;            /* method to use in estimating network */
  72.     short int squash;            /* squashing function to use */
  73.     short int valid;            /* FALSE if new network, TRUE if network has already been estimated */
  74.     short int prtitinfo;        /* flag to cause printing of estimates, etc. for each iteration */
  75.     short int saveout;            /* flag to cause save to file of all output */
  76.     }                    NeuralNet;
  77.  
  78. /*--------------------------- Prototypes ------------------------------*/
  79. /*---- Prototypes for Neural Network Main.c ----*/
  80.         main(void);
  81.         printf(char *, ...);
  82. FILE *     fopen(char *,char *);
  83.          fclose(FILE *);
  84.          fprintf(FILE *, char *, ...);
  85.         Estimate(void);
  86.         
  87. /*---- Prototypes for General.c ----*/
  88.         RestoreParms(DTypeVector *);
  89.         SaveParms(DTypeVector *);
  90.         NotYetAvail(void);
  91.         HandleOutOfMem(void);
  92.         
  93.         do_HookeJeeves(void);
  94.         ExMove(void);
  95.         PatMove(void);
  96.         SetInitStep(void);
  97.         AllotSearchWorkSpace(void);
  98.         LockSearchWorkSpace(void);
  99.         UnlockSearchWorkSpace(void);
  100.  
  101. /*---- Prototypes for Gradient methods.c ----*/
  102.         do_GaussNewton(void);
  103.         do_quasiGaussNewton(void);
  104.         ComputegradSSforqGN(void);
  105.         AppendResidZeros(void);
  106.         AppendMuIdentity(void);
  107.         LineSearch(double *);
  108.         ConstrainStep(void);
  109.         UpdateParms(DataType);
  110.         StopYet(double,int,int);
  111.         StopAtFirst(double);
  112. double    Compute_minlambda(void);
  113.         AllotGradientWorkSpace(void);
  114.         LockGradientWorkSpace(void);
  115.         UnlockGradientWorkSpace(void);
  116.  
  117. /*---- Prototypes for Ord Least Squares.c ----*/
  118.         OLSbyQRmethod(DTypeMatrix *,DTypeVector *,DTypeVector *,DTypeVector *);
  119.         ComputeQY(DTypeMatrix *,DTypeVector *,DTypeVector *);
  120.         SolveRbY(DTypeMatrix *,DTypeVector *,DTypeVector *);
  121.         QRDecomposition(DTypeMatrix *,DTypeVector *,DTypeVector *);
  122.         WriteYXToFile(FILE *, DTypeVector *, DTypeMatrix * );
  123.  
  124. /*---- Prototypes for Compute_SS.c ----*/
  125.             logisticSquash_dSquash(DTypeVector *,DTypeVector *);
  126. DataType     ComputeOutputJac(void);
  127.             ComputeJacobian(DataType *);
  128. double        Compute_SS_Jac(void);
  129.             logisticSquash(DTypeVector *);
  130. DataType     ComputeOutputOnly(void);
  131. double        Compute_SS(void);
  132.             HLock_Alpha_dSquash(void);
  133.             HUnlock_Alpha_dSquash(void);
  134.             HLock_Alpha(void);
  135.             HUnlock_Alpha(void);
  136.         
  137. /*---- Prototypes for Setup Network.c ----*/
  138.         SetupNetDefaults(void);
  139.         AllotInitNewNetWeights(void);
  140.         HLockNet(void);
  141.         HUnlockNet(void);
  142.         DisplayNet(void);
  143.         InitWeights(DTypeMatrix *);
  144.         SetupTolerances(void);
  145.  
  146. /*---- Prototypes for DTypeMatrix.c ----*/
  147.         AllotDTypeMatrix(DTypeMatrix *,int,int);
  148.         DisplayDTypeMatrix(DTypeMatrix *);
  149.         WriteMatrixToFile(FILE *,DTypeMatrix * );
  150.         ClearDTypeMatrix(DTypeMatrix *);
  151.         Matrix_by_Vec(DTypeMatrix *,DTypeVector *,DTypeVector *);    
  152.         Matrix_by_Diag(DTypeMatrix *,DTypeVector *,DTypeMatrix *);
  153.         Matrix_by_Matrix(DTypeMatrix *,DTypeMatrix *,DTypeMatrix *);
  154.  
  155. /*---- Prototypes for DTypeVector.c ----*/
  156. double        L2Norm(DTypeVector *);
  157. DataType     Vec_by_Vec(DTypeVector *,DTypeVector *);
  158.             CopyDTypeVector(DTypeVector *,DTypeVector *);
  159.             AllotDTypeVector(DTypeVector *,int);
  160.             DisplayDTypeVector(DTypeVector *);
  161.             WriteVectorToFile(FILE *,DTypeVector *);
  162.             ClearDTypeVector(DTypeVector *);
  163.         
  164. /*---- Prototypes for testdata.c ----*/
  165.         SetTestNet(NeuralNet *);
  166.         testData(NeuralNet *);
  167.         testJacobian(DTypeMatrix *,DTypeVector *,DTypeVector *,DTypeVector *);
  168.         testdepdata(NeuralNet *);
  169.  
  170.